package ginx

import "gitee.com/dn-jinmin/authx"

type (
	Option func(o *options)

	options struct {
		authx.Authx
		errResp    ErrResp
		dsn        string
		routeWhite map[string]string
		secret     string
		loadSrvApi bool
		loadAuth   bool
	}
)

func newOption(opts ...Option) *options {
	o := &options{
		routeWhite: make(map[string]string),
		loadSrvApi: true,
		loadAuth:   true,
	}
	for _, opt := range opts {
		opt(o)
	}
	return o
}

func WithDsn(dsn string) Option {
	return func(o *options) {
		o.dsn = dsn
	}
}

func WithRouteWhite(routeWhite map[string]string) Option {
	return func(o *options) {
		o.routeWhite = routeWhite
	}
}

func WithLoadSrvApi(loadSrvApi bool) Option {
	return func(o *options) {
		o.loadSrvApi = loadSrvApi
	}
}

func WithLoadAuth(secret string) Option {
	return func(o *options) {
		o.secret = secret
		o.loadAuth = true
	}
}

func WithAuthx(authx authx.Authx) Option {
	return func(o *options) {
		o.Authx = authx
	}
}

func WithErrResp(errResp ErrResp) Option {
	return func(o *options) {
		o.errResp = errResp
	}
}
